/**
 * 抖音关注：程序员三丙
 * 知识星球：https://t.zsxq.com/j9b21
 */
package sanbing.example.dylike.infrastructure.queue;

import lombok.Getter;
import org.apache.kafka.clients.consumer.ConsumerRecord;

import java.util.UUID;


public class QueueMsg {
    @Getter
    private final UUID key;
    @Getter
    private final QueueMsgHeaders headers;
    @Getter
    private final byte[] data;

    public QueueMsg(ConsumerRecord<String, byte[]> record) {
        this.key = UUID.fromString(record.key());
        QueueMsgHeaders headers = new DefaultQueueMsgHeaders();
        record.headers().forEach(header -> {
            headers.put(header.key(), header.value());
        });
        this.headers = headers;
        this.data = record.value();
    }

    public QueueMsg(UUID key, byte[] data) {
        this(key, data, new DefaultQueueMsgHeaders());
    }

    public QueueMsg(UUID key, byte[] data, QueueMsgHeaders headers) {
        this.key = key;
        this.data = data;
        this.headers = headers;
    }

}
